<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="./Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	    
	    <!--气泡提示所需文件-->
	    <script src="./Public/Admin/Public/jquery-1.8.2.min.js" type="text/javascript" charset="utf-8"></script>
	    <script src="./Public/Admin/Public/hdjs/hdjs.min.js" type="text/javascript" charset="utf-8"></script>
	    <link rel="stylesheet" type="text/css" href="./Public/Admin/Public/hdjs/hdjs.css"/>
	    <script src="./Public/jquery-1.8.2.min.js" type="text/javascript" charset="utf-8"></script>
	    <script type="text/javascript">
	    	//全选与反选

	        
	        
	        //$(this).attr("selected", "selected"); //选中
	        
	        
	        //异步部分开始
	       	$(function(){
	       		//oninput 事件在用户输入、退格、删除、剪切、粘贴及鼠标剪切与粘贴时触发
	       		$(document).on('input','.periods',function(event){
	       			//给输入框一个失去焦点事件（失去焦点时，触发函数）
	       		//$(".periods").blur(function(){
	       			
	       			//.val()获取文本框中的值
	       			var num = $(this).val();
//	       			alert(num);
	       			//发异步
	       			$.ajax({
	       				//请求方式
	       				type:"post",
	       				//请求地址
	       				url:"<?php echo U('periodsNum')?>",
	       				//发送数据
	       				//类似于<input type="text" name="p_num" value="num" />
	       				data:{p_num:num},
	       				//指定php返回的数据类型
	       				dataType:'json',
	       				//得到服务器的响应
	       				 // phpData就是服务器响应的数据，如果忘记写phpData ，虽然数据已经写入数据库，但是无法显示到页面上、
	       				success:function(phpData){
	       					if(phpData == 2){
	       						alert('请输入数字');
	       					}
	       					if(phpData == 1){
	       						alert('必须从第1期开始添加');
	       					}
	       					
	       					//设置一个变量，并给空字符串，这样goods可以拼接字符串。
	       					var goods = '';
	       					
	       					var temp = '';
	       					goods += '<tr><th><input id="checkAll" type="checkbox" /> 全选</th><th>商品名</th></tr>';
	       					//循环PHPData
	       					$.each(phpData,function(k,v){
	       						
	       						goods += '<tr><td width="100"><input name="goods_gid[]" type="checkbox" value=" '+ v.gid +' "/></td>';
	       						goods += '<td> '+ v.gname + ' </td></tr>';
	       					})
	       					
	       					temp += goods;
	       					$('.table').html(temp);
	       					
	       					//全选与反选
	       					$("#checkAll").click(function() {
	                			$('input[name="goods_gid[]"]').attr("checked",this.checked); 
	            			});
	       					
	       				}
	       				
	       			}) 	      			
	       		})
	       	})
	    </script>
	</head>
	<body>
		<form action="" method="post">
			<div class="alert alert-success">添加期数(已经添加过期数的和超过商品限定期数的都不会显示)</div>
			<div class="form-group">
				<label for="exampleInputEmail1">期数</label>
				<input id="exampleInputEmail1" class="form-control periods" type="text" name="periods">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">选择商品</label>
				<table id="goods" class="table table-hover">
				<!--<tr><th><input id="checkAll" type="checkbox" /> 全选</th><th>商品名</th></tr>
				<?php foreach ($goodsData as $v){?>
			  	<tr>
			  		<td width="100"><input name="goods_gid[]" type="checkbox" value="<?php echo $v['gid']?>"/></td>
			  		<td><?php echo $v['gname']?></td>
			  	</tr>
			  	<?php }?>-->
				</table>
				<!--<select name="goods_gid" class="form-control">
					<?php foreach ($goodsData as $v){?>
					<option value="<?php echo $v['gid']?>"><?php echo $v['gname']?></option>
					<?php }?>
				</select>-->
			</div>
			<button class="btn btn-primary btn-block" type="submit"> 确定 </button>
		</form>
	</body>
</html>
